<script setup lang="ts">
import { onMounted } from 'vue'
import * as echarts from 'echarts';

onMounted(() => {
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('leacharts'));

    // 指定图表的配置项和数据
    var option = {
        title: {
            "text": "出入库情况",
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: { // 坐标轴指示器，坐标轴触发有效
                type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            left: '2%',
            right: '4%',
            bottom: '14%',
            top: '16%',
            containLabel: true
        },
        legend: {
            data: ['出库', '入库'],
            right: 10,
            top: 12,
            textStyle: {
                color: "#000"
            },
            itemWidth: 12,
            itemHeight: 10,
            // itemGap: 35
        },
        xAxis: {
            type: 'category',
            data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
            axisLine: {
                lineStyle: {
                    color: 'black'

                }
            },
            axisLabel: {
                // interval: 0,
                // rotate: 40,
                textStyle: {
                    fontFamily: 'Microsoft YaHei'
                }
            },
        },

        yAxis: {
            type: 'value',
            max: '500',
            axisLine: {
                show: false,
                lineStyle: {
                    color: 'black'
                }
            },
            splitLine: {
                show: true,
                lineStyle: {
                    color: 'rgba(255,255,255,0.3)'
                }
            },
            axisLabel: {}
        },
        series: [{
            name: '出库',
            type: 'bar',
            barWidth: '15%',
            itemStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: '#fccb05'
                    }, {
                        offset: 1,
                        color: '#f5804d'
                    }]),
                },
            },
            data: [320, 332, 401, 334, 390, 320, 332, 301, 334, 390, 320, 332]
        },
        {
            name: '入库',
            type: 'bar',
            barWidth: '15%',
            itemStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: '#248ff7'
                    }, {
                        offset: 1,
                        color: '#6851f1'
                    }]),
                }
            },
            data: [220, 182, 191, 234, 290, 220, 182, 191, 234, 290, 220, 182]
        }]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option)
})

</script>

<template>
    <div id="leacharts" style="width: 100%;height:100%;"></div>
</template>
